import global from '@/utils/global'
import http from '@/utils/request'

export function loginByUsername(username, password) {
  return http({
    url: http.adornUrl(global.auth + '/authentication/form'),
    headers: { // application/json; charset=utf-8 //application/x-www-form-urlencoded; charset=utf-8
      'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
    },
    method: 'post',
    auth: {
      username: 'rainbow',
      password: 'rainbowsecret'
    },
    // transformRequest: [function(data) {
    //   // 对 data 进行任意转换处理
    //   return Qs.stringify(data)
    // }],
    data: http.adornData({
      'username': username,
      'password': password
    }, true, 'form')
  })
}

export function getUserInfo() {
  return http({
    url: http.adornUrl(global.auth + '/auth/me'),
    method: 'post'
  })
}

export function logout() {
  return http({
    url: http.adornUrl(global.auth + '/auth/jwtLogout'),
    method: 'get'
  })
}
